package com.snsoft.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import com.snsoft.util.Constants;

/**
 * 
 * @author 慎伟康
 * 
 * @date 2017年10月21日 下午7:50:13
 * 
 * @Description TODO
 *    设置请求响应对象编码
 */
@WebFilter("/*")
public class EncodeFilter implements Filter {

    public EncodeFilter() {
    }
    
    /**
     * 初始化方法
     */
    public void init(FilterConfig fConfig) throws ServletException {
    	// TODO Auto-generated method stub
    }


	/**
	 * 编码过滤
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		//设置请求编码
		request.setCharacterEncoding(Constants.CHARSET);
		
		//设置响应编码
		response.setCharacterEncoding(Constants.CHARSET);
		response.setContentType("application/json");
		chain.doFilter(request, response);
	}

	/**
	 * 销毁方法
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}
}
